package ynu.edu.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * 测试控制器
 * 用于验证Gateway服务本身是否正常运行
 */
@RestController
@RequestMapping("/test")
public class TestController {

    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    /**
     * 简单的ping测试
     */
    @GetMapping("/ping")
    public ResponseEntity<Map<String, Object>> ping() {
        Map<String, Object> response = new HashMap<>();
        response.put("message", "Gateway is working!");
        response.put("timestamp", LocalDateTime.now().format(FORMATTER));
        response.put("service", "gateway-service");
        response.put("port", 9000);
        response.put("status", "OK");
        
        return ResponseEntity.ok(response);
    }

    /**
     * 需要认证的测试接口
     */
    @GetMapping("/auth-required")
    public ResponseEntity<Map<String, Object>> authRequired() {
        Map<String, Object> response = new HashMap<>();
        response.put("message", "This endpoint requires authentication!");
        response.put("timestamp", LocalDateTime.now().format(FORMATTER));
        response.put("note", "If you see this, authentication passed");
        
        return ResponseEntity.ok(response);
    }
} 